package com.tanhua.server.controller;

import com.tanhua.server.service.MessagesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/messages")
@Slf4j
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 接口名称：公告列表
     * 接口路径：GET/messages/announcements
     *
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity<Object> announcements(@RequestParam(defaultValue = "1") Integer page,
                                                @RequestParam(defaultValue = "4") Integer pagesize) {

        return messagesService.findAll(page, pagesize);
    }

    /**
     *接口名称：点赞列表
     * 接口路径：GET/messages/likes
     *
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity<Object> likes(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        log.info("---------->点赞列表");

        if (page < 0) {
            page = 1;
        }

        return messagesService.likes(1, page, pagesize);
    }

    /**
     * 接口名称：喜欢列表
     * 接口路径：GET/messages/loves
     *
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity<Object> loves(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        log.info("----------->喜欢列表");

        if (page <0) {
            page = 1;
        }

        return messagesService.likes(3, page, pagesize);
    }

    /**
     * 接口名称：评论列表
     * 接口路径：GET/messages/comments
     *
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity<Object> comments(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer pagesize){
        log.info("----------->评论列表");

        if (page <0) {
            page = 1;
        }

        return messagesService.likes(2, page, pagesize);
    }
}
